/*
 * Project it.battlehorse.rcp.tools.dbbase
 * Created on Dec 2, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */ 
package it.battlehorse.rcp.tools.dbbase.widgets;

import it.battlehorse.rcp.tools.dbbase.DatasourceConfig;
import it.battlehorse.rcp.tools.dbbase.DbBaseActivator;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * A label provider which is bound to the {@code DbManager} and can be used to
 * populate a list of available datasources.
 * 
 * @author battlehorse
 * @since Dec 2, 2005
 */
public class DatasourceLabelProvider implements ILabelProvider, ITableLabelProvider {

	public String getText(Object element) {
		DatasourceConfig cfg = (DatasourceConfig) element;
		return cfg.getName();
	}
	
    public String getColumnText(Object obj, int index) {
        return getText(obj);

    }
    
    public Image getColumnImage(Object obj, int index) {
        return getImage(obj);
        	
    }	
	
	public Image getImage(Object element) {
		DatasourceConfig cfg = (DatasourceConfig) element;		
		return DbBaseActivator.getDefault().getDatabaseImage(
				cfg.getDatabase().getId(),
				cfg.getDatabase().getIcon());		
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
	 */
	public void addListener(ILabelProviderListener listener) {
		// nothing to do

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
	 */
	public void dispose() {
		// nothing to do

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
	 */
	public boolean isLabelProperty(Object element, String property) {		
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
	 */
	public void removeListener(ILabelProviderListener listener) {
		// nothing to do

	}

}
